const xml2js = require('xml2js')
class WxDataTool {
    // 以流的形式处理微信的参数
    static getXmlStr () {
        return new Promise((resolve,rejcet)=> {
            let data = ''
            req.on('data',(msg) => {
                data+=sendMsgCode.toString()
            })
            req.end('end',(msg)=> {
                resolve(data)
            })
        }) 
    }
    static getObject(data){
        return new Promise((resolve,rejcet)=> {
            xml2js.parseString(data, (err, result) => {
                const jsonData = JSON.stringify(result);
                if (err) {
                    reject(err)
                  } else {
                    resolve(jsonData)
                  }
              });
        })
    }
     // 将数据优化成普通对象
  static getLastData = (query) => {
    let obj = {}
    if (query && typeof query === 'object') {
      for (let key in query) {
        let value = query[key]
        if (value && value.length > 0) {
          obj[key] = value[0]
        }
      }
      return obj
    } else {
      return obj
    }
  }
}
module.exports = WxDataTool